import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from "./home/home.component";
import { ProductComponent } from "./product/product.component";
import { Product1Component } from "./product1/product1.component";
import { Product2Component } from "./product2/product2.component";
import { Product21Component } from "./product21/product21.component";
import { Product22Component } from "./product22/product22.component";
import { Code404Component } from "./code404/code404.component";
import { ChatComponent } from "./chat/chat.component";
import { LoginGuard } from "./guard/login.guard";
import { LoginComponent } from "./login/login.component";
import {UnsavedGuard} from "./guard/unsaved.guard";
import {ProductResolve} from "./guard/product.resolve";

const routes: Routes = [
  // 重定向
  {path: '', redirectTo: '/home', pathMatch: 'full'},
  {path: 'home', component: HomeComponent},
  {path: 'chat', component: ChatComponent, outlet: 'aux'},
  {path: 'product', component: ProductComponent},
  {path: 'product1/:id', component: Product1Component},
  {path: 'product2/:id', component: Product2Component, children: [
    {path: '', component: Product21Component},
    {path: 'product22/:id', component: Product22Component}
  ], canActivate: [LoginGuard],// 守护路由
    canDeactivate: [UnsavedGuard]},// 守护路由
  {path: 'login', component: LoginComponent},
  // 找不到页面跳转到错误404页面
  {path: '**', component: Code404Component}
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule],
  providers: [LoginGuard,UnsavedGuard,ProductResolve]
})
export class AppRoutingModule { }
